<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>跳转到百度</button>
    <div></div>
    <script>
        /* 
            Location 接口表示其链接到的对象的位置（URL）。
            href:跳转的路径
        */
        const btnObj = document.querySelector("button");
        btnObj.addEventListener("click", function () {
            location.href = "https://www.baidu.com";
        })

        let time = 3;
        const divObj = document.querySelector("div");
        setInterval(function () {
            if (time != 0) {
                divObj.innerText = '将在' + time + '秒后跳转到百度';
                time--;
            } else {
                location.href = "https://www.baidu.com";
            }
        }, 1000);
    </script>
</body>

</html>